
package cjos.conexionBD;

import java.sql.*;

/**
 *
 * @author Jos
 */
public class ConexionOracle {

    public void conexionDirectaOracle() throws SQLException {

        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

        StringBuilder sql = new StringBuilder();
        PreparedStatement pst = null;
        ResultSet rs = null;
        Connection conn = null;
        sql.append("select BANNER from SYS.V_$VERSION");
        try {
            conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "joscorp", "J0simar");
            pst = conn.prepareStatement(sql.toString());
            //pst.setString(1, id_user);
            rs = pst.executeQuery();
            while (rs.next()) {
                System.out.println(rs.getString(1));
            }
        } catch (Exception e) {
            System.out.println("ERROR: " + e);
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
                if (pst != null) {
                    pst.close();
                }
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception ex) {
                System.out.println("ERROR: " + ex);
            }
        }

    }

    public static void main(String args[]) throws SQLException {
        ConexionOracle c = new ConexionOracle();
        c.conexionDirectaOracle();
    }
}
